package com.only4play.usercenter.service.impl;

import com.only4play.usercenter.config.ApplicationServerConfiguration;
import com.only4play.usercenter.mapper.RequestLogMapper;
import com.only4play.usercenter.model.RequestLog;
import com.only4play.usercenter.service.RequestLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * @author liyuncong
 * @version 1.0
 * @file RequestLogServiceImpl
 * @brief RequestLogServiceImpl
 * @details RequestLogServiceImpl
 * @date 2024-05-21
 *
 * Edit History
 * ----------------------------------------------------------------------------
 * DATE                     NAME               DESCRIPTION
 * 2024-05-21               liyuncong          Created
 */

@Slf4j
@Service
public class RequestLogServiceImpl implements RequestLogService<RequestLog> {

    @Autowired
    private ApplicationServerConfiguration serverConfiguration;
    @Autowired
    private RequestLogMapper requestLogMapper;

    // 初始化一个队列存放日志
    private final Queue<RequestLog> queue;

    public RequestLogServiceImpl() {
        queue = new LinkedBlockingQueue<>();
    }

    @Override
    public Boolean isEmpty() {
        return this.queue.isEmpty();
    }

    @Override
    public int size() {
        return this.queue.size();
    }

    @Override
    public RequestLog poll() {
        return this.queue.poll();
    }

    @Override
    public void offer(RequestLog log) {
        this.queue.offer(log);
    }

    @Override
    public Boolean insertBatch(List<RequestLog> logs) {
        return requestLogMapper.insertBatchLog(logs) > 0;
    }
}
